﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using MyVoteMVC.Data.Repositories;
using MyVoteMVC.Domain;
using MyVoteMVC.Data;
using MyVoteMVC.Common;
using MyVoteMVC.Service;
using MyVoteMVC.Models;
using MyVoteMVC.Extensions;

namespace MyVoteMVC.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            //IUnitOfWork unitOfWork = Factory.GetInstance<IUnitOfWork>();
            //var repository = unitOfWork.GetRepository<VT_Activities>();
            //IList<VT_Activities> list = repository.GetAll().ToList();


            //IActivityImageService service = Factory.GetInstance<IActivityImageService>();

            //IAuserService auserService = Factory.GetInstance<IAuserService>();
            //auserService.AddUer("sss", "ddd", "123", "asd");

            //IActivityService activityService = Factory.GetInstance<IActivityService>();

            //IModelConverter<VT_Activities, Activity> convert;
            //activityService.GetActivitiesList(DateTime.Now, DateTime.Now).ToModelList(convert);
            MyVoteMVC.Models.Ticket.ContentDetailContainer container = new Ticket.ContentDetailContainer();
            container.Activity = new ActivityInContent()
            {
                Id = "ActivityInContent",
                Questions = new List<QuestionInContent>() {
                    new QuestionInContent(){ 
                        Items = new List<ItemInContent>(){
                            new ItemInContent()
                            { 
                                Id = "1"
                            },
                            new ItemInContent()
                            { 
                                Id = "3"
                            },
                            new ItemInContent()
                            { 
                                Id = "2"
                            }
                        }, 
                        Id = "QuestionInContent" 
                    },
                    new QuestionInContent(){ 
                        Items = new List<ItemInContent>(){
                            new ItemInContent()
                            { 
                                Id = "1"
                            },
                            new ItemInContent()
                            { 
                                Id = "3"
                            },
                            new ItemInContent()
                            { 
                                Id = "2"
                            }
                        }, 
                        Id = "QuestionInContent" 
                    },
                    new QuestionInContent(){ 
                        Items = new List<ItemInContent>(){
                            new ItemInContent()
                            { 
                                Id = "1"
                            },
                            new ItemInContent()
                            { 
                                Id = "3"
                            },
                            new ItemInContent()
                            { 
                                Id = "2"
                            }
                        }, 
                        Id = "QuestionInContent" 
                    }
                },
                 
            };
            string containerstr = container.ToString();
            MyVoteMVC.Models.Ticket.ContentDetailContainer containerv2 = new Ticket.ContentDetailContainer(containerstr);
            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        //public ActionResult AddUser(string UserName)
        //{
        //    IUserService userService = Factory.GetInstance<IUserService>();
        //    userService.Register(UserName, UserName, UserName);
        //    return Content("{success:true}");
        //}

        public ActionResult LoginUser(string UserName, string UserPass)
        {
            IUserService userService = Factory.GetInstance<IUserService>();
            var pUser = userService.UserLogin(UserName,UserPass);
            if (null != pUser)
                return Content("{success:true}");
            else
                return Content("{success:false}");
        }

        public ActionResult ModifyUserPass(string UserName, string OldPass, string NewPass)
        {
            IUserService userService = Factory.GetInstance<IUserService>();
            var pResult = userService.ChangePassword(UserName, OldPass, NewPass);
            if (pResult)
                return Content("{success:true}");
            else
                return Content("{success:false}");
        }

        public ActionResult Extjs()
        {
            return View();
        }

        public ActionResult ExtjsAccess()
        {
            return View();
        }

        public ActionResult DemoPage()
        {
            return View();
        }

        public ActionResult Details()
        {
            return View();
        }
    }
}
